package com.example.myapplication.old;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.os.Bundle;

import com.example.myapplication.R;
import com.example.myapplication.old.adapter.GoodsAdapter;
import com.example.myapplication.old.entity.Goods;

import java.util.ArrayList;
import java.util.List;

public class GoodsActivity extends AppCompatActivity {
    private Context context;
    private RecyclerView recyclerView;
    private List<Goods> goodslist = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context=this;
        setContentView(R.layout.activity_goods);
        recyclerView=findViewById(R.id.recyclerlist);
        //设置布局管理器
        RecyclerView.LayoutManager manager = new GridLayoutManager(context,2);
        recyclerView.setLayoutManager(manager);
        //设置适配器
        GoodsAdapter adapter = new GoodsAdapter();
        recyclerView.setAdapter(adapter);
        initData();
        adapter.setDate(goodslist);

    }
    private void initData(){
        for (int i = 0; i < 20; i++) {
           Goods good = new Goods();
           good.setImg(i%2==0?R.drawable.a1:R.drawable.a2);
           good.setName("巨龙传说"+i);
           good.setPrice(20+i);
           good.setCount(i);
           goodslist.add(good);
        }
    }
}